package common;

import java.util.List;
import java.util.Objects;

public class Rule {
    public String forward;
    int prefixLen;
    public long ip;
    public int hit;
    public int match;
    public int lecIndex;

    public Rule(long ip, int prefixLen, String forward){
        this.ip = ip;
        this.prefixLen = prefixLen;
        this.forward = forward;
        this.lecIndex = -1;
    }


    public int getPriority() {
        return prefixLen;
    }

    public int getHit(){
        return hit;
    }

    @Override
    public String toString() {
        return String.format("%s %s %s %s %s", ip, prefixLen, forward, match, hit);
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Rule rule = (Rule) o;
        return prefixLen == rule.prefixLen && ip == rule.ip && Objects.equals(forward, rule.forward);
    }

    @Override
    public int hashCode() {
        return Objects.hash(forward, prefixLen, ip);
    }
}
